<template>
<div style="width: 50%;margin: 5px auto">
  <div class="card">
    <div style="font-weight: bold;font-size: 24px;margin-bottom: 50px">发表新博客</div>
    <el-form :model="form" label-width="100px" style="padding-right: 50px" :rules="rules" ref="formRef">
      <el-form-item label="标题" prop="title">
        <el-input v-model="form.title" placeholder="标题"></el-input>
      </el-form-item>
      <el-form-item label="简介" prop="descr">
        <el-input type="textarea" v-model="form.descr" placeholder="简介"></el-input>
      </el-form-item>
      <el-form-item label="标签" prop="tags">
        <el-select v-model="tagsArr" multiple filterable allow-create default-first-option style="width: 100%">
          <el-option value="家用汽车"></el-option>
          <el-option value="商用汽车"></el-option>
          <el-option value="专用车"></el-option>
          <el-option value="内燃机汽车"></el-option>
          <el-option value="电动汽车"></el-option>
          <el-option value="混合动力汽车"></el-option>
          <el-option value="轿车"></el-option>
          <el-option value="SUV"></el-option>
          <el-option value="MPV"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="内容" prop="content">
        <el-input type="textarea" v-model="form.content" placeholder="内容"></el-input>
      </el-form-item>

    </el-form>
    <div style="text-align: center"><el-button type="primary" size="medium" style="width: 100px" @click="save">保 存</el-button> </div>
  </div>
</div>
</template>

<script>
export default {
  name: "NewBlog",
  data(){
    return{
      form: {},
      user: JSON.parse(localStorage.getItem('xm-user') || '{}'),
      rules: {

      },
      tagsArr:[],
      editor:null,
      blogId:this.$route.query.blogId
    }
  },
  mounted() {
  },
  created() {
  },
  methods:{
    save() {
      this.$refs.formRef.validate((valid) => {
        if (valid) {
          this.form.tags = JSON.stringify(this.tagsArr)
          this.$request({
            url: this.form.id ? '/blog/update' : '/blog/add',
            method: this.form.id ? 'PUT' : 'POST',
            data: this.form
          }).then(res => {
            if (res.code === '200') {
              this.$message.success('保存成功')
            } else {
              this.$message.error(res.msg)
            }
          })
        }
      })
    },
    handleCoverSuccess(res){
      this.form.cover = res.data;
    },
  }
}
</script>

<style scoped>

</style>